package com.example.demo.web;

import com.example.demo.domain.props.MinioProp;
import com.example.demo.service.CommService;
import com.example.demo.service.TestAuyowiredService;
import io.swagger.annotations.Api;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.net.URLEncoder;

/**
 * @Author: 聂吉泽
 * @Description:
 * @Date: create in 2021/11/18 9:19
 */
@RequestMapping("/api")
@RestController
@Api("通用工具类")
public class CommController {

    @Resource
    MinioProp minioProp;

    /**
     * 1.
     * @Qualifier("Autowired1ServiceImpl")
     * @Autowired   byType
     *
     * 2.使目前采用
     * byName
     */
    @Resource(name = "Autowired1ServiceImpl")
    TestAuyowiredService testAuyowiredService;

    @Resource
    private CommService commService;

    @GetMapping("/minioConfig")
    public MinioProp findMinioProp(){
        return minioProp;
    }

    @PostMapping("/upload")
    public void upload(MultipartFile file) throws Exception {
        commService.upload(file);
    }

    @GetMapping("/download")
    public void download(@RequestParam String fileName,HttpServletResponse response) throws Exception {
        commService.download(fileName,response);

    }

    @GetMapping("/downloadZip")
    public void downloadZip(@RequestParam String fileName,HttpServletResponse response) throws Exception {
        commService.downloadZip(fileName,response);
    }

    @GetMapping("/aotowired")
    public String aotowired(){
        return testAuyowiredService.test1();
    }

}
